<?php
namespace app\command;

use app\common\model\DataRecordModel;
use app\stores\model\order\GoodsOrderModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class Orderdelete extends Command
{
    protected function configure()
    {
        $this->setName('Orderdelete')
            ->addArgument('name', Argument::OPTIONAL, "your name")
            ->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
            ->setDescription('Say Hello');
    }

    protected function execute(Input $input, Output $output)
    {
        $datarecord= new DataRecordModel();
        $record_id=3;
        $record=$datarecord->where(['id'=>$record_id])->find();
        $old_id=empty($record)?0:$record['old_id'];
        $page=1;
        $num=20;
        $order['order_id']='asc';
        do{
            $s=[];
            $s[]=['is_paid','=',0];
            $s[]=['is_delete','=',0];
            $s[]=['status','=',1];
            $s[]=['add_time','<=',time()-60*30];
            $s[]=['order_id','>',$old_id];
            $list=GoodsOrderModel::where($s)->order($order)->limit($num)->page($page)->select()->toArray();
            if(empty($list)){
                $output->writeln("暂无数据".var_export([$s,$order,$page],true) );exit();
            }
            $up['status']='-1';
            $up['edit_time']=date('Y-m-d H:i:s');
            foreach ($list as $v){
                GoodsOrderModel::update($up,['order_id'=>$v['order_id']]);
            }
            $end=end($list);
            $old_id=$end['order_id'];
            $up=[];
            $up['old_id']=$old_id;
            $up['edittime']=date('Y-m-d H:i:s');
            DataRecordModel::up($up,['id'=>$record_id]);
        }while(true);
    }
}